// 绘制文字
import { getObjProperty } from '../utils';
import BaseElement from './element';
class Text extends BaseElement {
    constructor(opts) {
        super(opts);
        let style = getObjProperty(opts, 'style', {});
        let action = getObjProperty(opts, 'action', {});
        let fontStyle = getObjProperty(style, 'fontStyle', 'normal');
        let fontWeight = getObjProperty(style, 'fontWeight', 'normal');
        let fontSize = getObjProperty(style, 'fontSize', '14');
        let fontFamily = getObjProperty(style, 'fontFamily', 'sans-serif');
        this.text = getObjProperty(style, 'text', '');
        this.font = `${fontStyle} ${fontWeight} ${fontSize}px ${fontFamily}`;
        this.textAlign = getObjProperty(style, 'textAlign', 'center');
        this.textBaseline = getObjProperty(style, 'textBaseline', 'middle');

        this.stroke = getObjProperty(action, 'stroke', false);
        this.fill = getObjProperty(action, 'fill', true);
        this.fillStyle = getObjProperty(style, 'fillStyle', '#333333');
    }

    draw(ctx) {
        let { x, y } = this.points[0];
        let text = this.text;

        ctx.font = this.font;
        ctx.textAlign = this.textAlign;
        ctx.textBaseline = this.textBaseline;
        if (this.fill) {
            ctx.fillStyle = this.fillStyle;
            ctx.fillText(text, x, y);
        }
        if (this.stroke) {
            ctx.strokeText(text, x, y);
        }

        ctx.font = `normal normal 14px sans-serif`;
    }

    addPoint() {}
    update() {}
}
export default Text;
